//
//  CustomImageButton.m
//  Kugou-OC
//
//  Created by BH on 16/5/27.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "CustomImageButton.h"
#import "GlobalDefine.h"

#define IMAGEHEIGHT_RATIO 0.6

@implementation CustomImageButton

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = TITLE_FOUR_FONT;
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return self;
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat imageY = 10;
    CGFloat imageH = self.frame.size.height*IMAGEHEIGHT_RATIO-10;
    CGFloat imageW = self.frame.size.width*0.38;
    CGFloat imageX = (self.frame.size.width-imageW) / 2;
    
    return CGRectMake(imageX, imageY, imageW, imageH);
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleX = 0;
    CGFloat titleY = self.frame.size.height*IMAGEHEIGHT_RATIO;
    CGFloat titleW = self.frame.size.width;
    CGFloat titleH = self.frame.size.height*(1-IMAGEHEIGHT_RATIO);
    
    return CGRectMake(titleX, titleY, titleW, titleH);
}

@end
